package com.xx.sg.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.xx.sg.own.entity.AlarmVideo;
import com.xx.sg.own.service.AlarmVideoService;
import com.xx.sg.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/alarmVideo")
@Tag(name = "火情视频绑定", description = "火情视频绑定")
public class AlarmVideoController {

    @Autowired
    private AlarmVideoService alarmVideoService;


    @GetMapping("/list")
    @Operation(summary = "获取列表", description = "获取列表")
    public R list(AlarmVideo alarmVideo) {
        LambdaQueryWrapper<AlarmVideo> wrapper = new LambdaQueryWrapper<AlarmVideo>();
        wrapper.eq(StringUtils.isNotBlank(alarmVideo.getAlarmId()), AlarmVideo::getAlarmId, alarmVideo.getAlarmId())
                .eq(StringUtils.isNotBlank(alarmVideo.getName()), AlarmVideo::getName, alarmVideo.getName());
        return R.success(alarmVideoService.list(wrapper));
    }

    @GetMapping("/fireVedio/{alarmId}")
    @Operation(summary = "获取火情对应列表", description = "获取火情对应列表")
    public R fireVideo(@PathVariable("alarmId") String alarmId) {
        LambdaQueryWrapper<AlarmVideo> wrapper = new LambdaQueryWrapper<AlarmVideo>();
        wrapper.eq(AlarmVideo::getAlarmId, alarmId);
        return R.success(alarmVideoService.list(wrapper));
    }

    @PostMapping("/add")
    @Operation(summary = "新增火情视屏", description = "新增火情视屏")
    public R add(@RequestBody AlarmVideo alarmVideo) {
        alarmVideoService.save(alarmVideo);
        return R.success();
    }

    @GetMapping("/remove/{id}")
    @Operation(summary = "删除火情视屏", description = "删除火情视屏")
    public R remove(@PathVariable("id") String id) {
        return R.success(alarmVideoService.removeById(id));
    }

    @PostMapping("/remove")
    @Operation(summary = "删除火情视屏", description = "删除火情视屏")
    public R remove(@RequestBody AlarmVideo alarmVideo) {
        LambdaQueryWrapper<AlarmVideo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(alarmVideo.getSrc()), AlarmVideo::getSrc, alarmVideo.getSrc())
                .eq(StringUtils.isNotBlank(alarmVideo.getAlarmId()), AlarmVideo::getAlarmId, alarmVideo.getAlarmId());
        alarmVideoService.remove(wrapper);
        return R.success();
    }
}
